﻿<%@ Page Title="" Language="C#" MasterPageFile="~/Site.Master" AutoEventWireup="true" CodeBehind="userList_test.aspx.cs" Inherits="WingtipToys.Account.userList_test" %>

<script runat="server">

    

</script>
<asp:Content ID="Content1" ContentPlaceHolderID="MainContent" runat="server">
    <h3>FormView Example</h3>

    <table cellspacing="10">

        <tr>
            <td>
                <asp:GridView ID="userGridView"
                    DataSourceID="userSqlDataSource"
                    AutoGenerateColumns="false"
                    DataKeyNames="userID"
                    OnSelectedIndexChanged="userGridView_OnSelectedIndexChanged"
                    runat="Server">

                    <HeaderStyle BackColor="Navy"
                        ForeColor="White" />

                    <Columns>

                        <asp:ButtonField Text="Details..."
                            HeaderText="Show<BR>Details"
                            CommandName="Select" />

                        <asp:BoundField DataField="userID" HeaderText="USER ID" />
                        <asp:BoundField DataField="userName" HeaderText="User Name" />
                        <asp:BoundField DataField="roleName" HeaderText="Role Name" />

                    </Columns>

                </asp:GridView>

            </td>

            <td valign="top">

                <asp:FormView ID="userFormView"
                    DataSourceID="userDetailsSqlDataSource"
                    DataKeyNames="userID"
                    GridLines="Both"
                    OnItemUpdated="userFormView_ItemUpdated"
                    OnItemDeleted="userFormView_ItemDeleted"
                    runat="server">

                    <HeaderStyle BackColor="Navy"
                        ForeColor="White" />

                    <RowStyle BackColor="White" />

                    <EditRowStyle BackColor="LightCyan" />

                    <ItemTemplate>
                        <table>
                            <tr>Actions</tr>
                            <tr>
                                <td colspan="2">
                                    <asp:LinkButton ID="EditButton"
                                        Text="Edit"
                                        CommandName="Edit"
                                        runat="server" />
                                    &nbsp;
                        <asp:LinkButton ID="NewButton"
                            Text="New"
                            CommandName="New"
                            runat="server" />
                                    &nbsp;
                        <asp:LinkButton ID="DeleteButton"
                            Text="Delete"
                            CommandName="Delete"
                            runat="server" />
                                </td>
                            </tr>
                        </table>
                    </ItemTemplate>

                    <EditItemTemplate>
                        <table>
                            <tr>
                                <td align="right"><b>User ID:</b></td>
                                <td><%# Eval("UserID") %></td>
                            </tr>

                            <tr>
                                <td align="right"><b>User Name:</b></td>
                                <td>
                                    <asp:TextBox ID="EditFirstNameTextBox"
                                        Text='<%# Bind("userName") %>'
                                        runat="Server" /></td>
                            </tr>

                            <tr>
                                <td align="right"><b>Role Name:</b></td>
                                <td>
                                    <asp:TextBox ID="EditLastNameTextBox"
                                        Text='<%# Bind("RoleName") %>'
                                        runat="Server" /></td>
                            </tr>
                            <tr>
                                <td colspan="2">
                                    <asp:LinkButton ID="UpdateButton"
                                        Text="Update"
                                        CommandName="Update"
                                        runat="server" />
                                    &nbsp;
                        <asp:LinkButton ID="CancelUpdateButton"
                            Text="Cancel"
                            CommandName="Cancel"
                            runat="server" />
                                </td>
                            </tr>
                        </table>
                    </EditItemTemplate>

                    

                </asp:FormView>

            </td>

        </tr>

    </table>

    <asp:SqlDataSource ID="userSqlDataSource"
        SelectCommand="select AspNetUserRoles.UserId, AspNetUsers.UserName, AspNetRoles.Name as RoleName from AspNetUserRoles  inner join AspNetUsers on AspNetUsers.Id = AspNetUserRoles.UserId inner join AspNetRoles on AspNetUserRoles.RoleId = AspNetRoles.Id"
        ConnectionString="<%$ ConnectionStrings:DefaultConnection%>"
        runat="server"></asp:SqlDataSource>

    <asp:SqlDataSource ID="userDetailsSqlDataSource"
        SelectCommand="select AspNetUserRoles.UserId, AspNetUsers.UserName, AspNetRoles.Name as RoleName from AspNetUserRoles  inner join AspNetUsers on AspNetUsers.Id = AspNetUserRoles.UserId inner join AspNetRoles on AspNetUserRoles.RoleId = AspNetRoles.Id"
        InsertCommand="INSERT INTO AspNetUsers(UserName,id) VALUES (@UserName,); 
                        "

        UpdateCommand="UPDATE AspNetUsers SET UserName=@UserName WHERE id=@id;
                       UPDATE AspNetRoles SET name=@roleName WHERE id=@id;
                      "
        
        DeleteCommand="DELETE AspNetUsers WHERE 1=0"
        
        ConnectionString="<%$ ConnectionStrings:DefaultConnection%>"
        OnInserted="UserDetailsSqlDataSource_OnInserted"
        runat="server">

        

        <InsertParameters>
            <asp:Parameter Name="UserName" Direction="Output" Type="String" DefaultValue="0" />
        </InsertParameters>

        <UpdateParameters>
            <asp:Parameter Name="UserName" Direction="Output" Type="String" DefaultValue="0" />
            <asp:Parameter Name="roleName" Direction="Output" Type="String" DefaultValue="0" />
            <asp:Parameter Name="id" Direction="Output" Type="String" DefaultValue="0" />
        </UpdateParameters>

    </asp:SqlDataSource>


</asp:Content>
